package com.hy.controller;

import com.hy.bean.*;
import com.hy.service.BuytableService;
import com.hy.service.impl.BuytableServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Buytable)表控制层
 *
 * @author makejava
 * @since 2024-05-14 22:03:32
 */
@CrossOrigin
@RestController
@RequestMapping("buytable")
public class BuytableController {
    /**
     * 服务对象
     */
    @Resource
    private BuytableService buytableService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @RequestMapping("/list")
    public RespBean queryByPage(Integer page,Integer limit) {
        List<Map<String,Object>> buytables = new ArrayList<>();
        long count = 0l;
        try {
            buytables = buytableService.queryAllByLimit(page, limit);
            count = buytableService.count();
        } catch (Exception e) {
            e.printStackTrace();
        }
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",buytables);
        map.put("total",count);
        return RespBean.success("数据查询成功", map);
    }

    @RequestMapping("/details")
    public RespBean queryDetails(Integer id,Integer page,Integer limit) {
        List<Map<String,Object>> buytables = new ArrayList<>();
        long count = 0l;
        try {
            buytables = buytableService.queryAllDetails(id,page, limit);
            count = buytableService.countDetails(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",buytables);
        map.put("total",count);
        return RespBean.success("数据查询成功", map);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/getById/{id}")
    public Buytable queryById(@PathVariable("id") Integer id) {
        return null;
    }

    /**
     * 新增数据
     *
     * @param buytable 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public RespBean add(Buytable buytable) {
        return null;
    }

    /**
     * 编辑数据
     *
     * @param buytable 实体
     * @return 编辑结果
     */
    @PutMapping("/update")
    public RespBean edit(Buytable buytable) {
        return null;
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/deleteByid/{id}")
    public RespBean deleteById(@PathVariable("id") Integer id) {
        return null;
    }

    @GetMapping("/queryBuyTableState")
    public RespBean queryBuyTableState(String state) {
        return buytableService.getBuyTableState(state);
    }

}

